local hx__shanguangren = fk.CreateSkill{
    name = "hx__shanguangren",

    tags = {Skill.Compulsory},
}

fk.MagicDamage = 8
Fk:addDamageNature(fk.MagicDamage, "magic_damage", true)

hx__shanguangren:addEffect(fk.BeforeHpChanged,{
  can_refresh = function(self, event, target, player, data)
    return player == target and data.damageEvent and data.damageEvent.damageType == fk.MagicDamage
  end,
  on_refresh = function (self, event, target, player, data)
    data.num = data.num - data.shield_lost
    data.shield_lost = 0
    --player.room:broadcastPlaySound("./packages/moepack/audio/card/charm_damage")
    player.room:delay(200)
  end,
})

hx__shanguangren:addEffect(fk.DamageInflicted,{
    priority = 2,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__shanguangren.name) and target and target == player 
    end,
    on_cost = function (self, event, target, player, data)
        return data.damage and data.damageType == fk.NormalDamage
    end,
    on_use = function (self, event, target, player, data)
        data:preventDamage()
    end,
})

hx__shanguangren:addEffect(fk.DamageCaused,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(hx__shanguangren.name) and target and target == player 
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        if player:getMark("hx__shanguangren__huanwei") > 0 then
            local num = player:getMark("hx__shanguangren__huanwei")
            data:changeDamage(num)
        end
        data.damageType = fk.MagicDamage
    end,
})

hx__shanguangren:addAcquireEffect(function (self, player, is_start)
    local room = player.room
    room:setPlayerMark(player,"hx__shanguangren__seatrecord",player.seat)
end)

hx__shanguangren:addEffect(fk.AfterSkillEffect,{
    can_refresh = function (self, event, target, player, data)
    return player:hasSkill(hx__shanguangren.name) 
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if player:getMark("hx__shanguangren__seatrecord") ~= 0 then
            if player.seat ~= player:getMark("hx__shanguangren__seatrecord") then
                room:addPlayerMark(player,"hx__shanguangren__huanwei",1)
            end
        end
        room:setPlayerMark(player,"hx__shanguangren__seatrecord",player.seat)
    end
})

return hx__shanguangren